package com.nf.health.app.mine.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;

import com.nf.health.app.R;
import com.nf.health.app.activity.global.BaseActivity;
import com.nf.health.app.customview.PickerView;
import com.nf.health.app.customview.PickerView.onSelectListener;
import com.nf.health.app.utils.PreferenceHelper;
import com.nf.health.app.utils.ViewUtil;

import java.util.ArrayList;
import java.util.List;

/** 
 * @ClassName: NationActivity 
 * @Description:民族修改页面
 * @author Ian 
 * @date 2015-11-23 上午11:18:51 
 *  
 */
public class NationActivity extends BaseActivity {

	private ImageView sex_img;
	private String type = "";
	private String sex;
	private String nation = "";
	private PickerView pv_card;
	private List mlist;

	private Button next_btn;

	private String[] mz = {"汉族","蒙古族","满族","朝鲜族","赫哲族","达斡尔族","鄂温克族","鄂伦春族","回族","东乡族","土族","撒拉族","保安族","裕固族","维吾尔族",
			"哈萨克族","柯尔克孜族","锡伯族","塔吉克族","乌孜别克族","俄罗斯族","塔塔尔族","藏族","门巴族","珞巴族","羌族","彝族","白族","哈尼族","傣族","傈僳族",
			"佤族","拉祜族","纳西族","景颇族","布朗族","阿昌族","普米族","怒族","德昂族","独龙族","基诺族","苗族","布依族","侗族","水族","仡佬族","壮族","瑶族","仫佬族",
			"毛南族","京族","土家族","黎族","畲族","高山族"};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setTitleBar(R.layout.titlebar_base);
		setContent(R.layout.activity_nation);

		ViewUtil.setText(this, R.id.titlebar_title_tv,"民族");
		type = getIntent().getStringExtra("type");
		initView();
	}

	private void initView() {
		// TODO Auto-generated method stub
		sex_img = (ImageView) this.findViewById(R.id.sex_img);
		next_btn = (Button) findViewById(R.id.next_btn);

		if (type.equals("1")) {
			sex = PreferenceHelper.getString(PreferenceHelper.USERSEX, "1");
		}
		if (sex.equals("1")) {
			sex_img.setBackgroundResource(R.drawable.ka2);
		} else {
			sex_img.setBackgroundResource(R.drawable.ka);
		}

		pv_card = (PickerView)findViewById(R.id.pv_card);


		mlist = new ArrayList();

		for(int i=0;i< mz.length;i++){
			mlist.add(mz[i]);
		}

		pv_card.setData(mlist);
		pv_card.setOnSelectListener(new onSelectListener() {

			@Override
			public void onSelect(String text, int position) {
				nation = text;
			}
		});

		next_btn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				if(TextUtils.isEmpty(nation)){
					showToast("你还没有选中民族");
				}else{
					//网络请求
					if (type.equals("1")) {
						provider.requestUpdateUser(null, null, null, null, null, null,null ,nation,null,"updatanation");
					}
				}
			}
		});

	}
	@Override
	public void handleActionSuccess(String actionName, Object object) {
		super.handleActionSuccess(actionName, object);
		if (actionName.equals("updatanation")) {
			showToast("修改成功！");
			finish();
		}
	}
}